﻿#ifndef DATAWRITER_H
#define DATAWRITER_H


#include <QObject>
#include "xlsxdocument.h"
#include "general.h"
#include "logreader.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QMutex>
#include "xlsxworksheet.h"


using namespace QXlsx;

class DataWriter : public QObject
{
    Q_OBJECT
public:
    explicit DataWriter(QObject *parent = nullptr);
    DataWriter(AbstractSheet *sheet);
    template<typename T>
    QString translationRule(QString rule, int row);
    QVariant readCell(int row, int col);
    template<typename T>
    T getValueByRule(QString rule, int row);
    template<typename T>
    void writeValue(T value, int row, int col);
    // QStringList getSheetsName();
    // bool setActivateSheet(QString sheetName);
    // int getTotalRows();
    void setParam(QString m_LogDir, QJsonObject colObj, QHash<QString, QJsonObject> logFilters, QString logEndStr, quint16 start, quint16 count);
    void run();
    void run1();


signals:
    void threadFinished();
    void processedOneLine();
    void processedOneFile();
    // FileReader interface
// public:
//     bool readFile();

private:

    Worksheet *sheet = nullptr;
    QString m_LogDir;
    QJsonObject m_ColObj;
    QHash<QString, QJsonObject> m_LogFilters;
    QString m_LogEndStr;
    quint16 m_Start;
    quint16 m_Count;
    QMutex mutex;
};





#endif // DATAWRITER_H
